package com.kushe.site.controller;

import com.kushe.dao.DesignDao;
import com.kushe.dao.ImagesDao;
import com.kushe.dao.SortDao;
import com.kushe.dao.UserDao;
import com.kushe.util.KSController;
import com.kushe.util.core.DaoFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by WhiteBlue on 15/3/27.2
 */


@org.springframework.stereotype.Controller
public class IndexController extends KSController {

    @RequestMapping(value = "", method = {RequestMethod.HEAD, RequestMethod.GET})
    public Object index(HttpServletRequest request) {
        clearAttr(request);
        DesignDao designDao = DaoFactory.getDao(DesignDao.class);
        UserDao userDao = DaoFactory.getDao(UserDao.class);
        ImagesDao imagesDao = DaoFactory.getDao(ImagesDao.class);
        SortDao sortDao = DaoFactory.getDao(SortDao.class);
        this.setAttr("hotSort", sortDao.listIndex());
        this.setAttr("hotList", designDao.getHotForIndex());
        this.setAttr("newList", designDao.getNewForIndex());
        this.setAttr("hotUser", userDao.getForIndex());
        this.setAttr("hotImages", imagesDao.getForIndex());
        return this.render("/index.html");
    }

    @RequestMapping(value = "/search", method = RequestMethod.GET)
    public Object search(@RequestParam(value = "content", required = true) String content, HttpServletRequest request) {
        clearAttr(request);
        DesignDao designDao = DaoFactory.getDao(DesignDao.class);
        return this.render("/login.html");
    }


    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public Object login(HttpServletRequest request) {
        clearAttr(request);
        return this.render("/login.html");
    }


    @RequestMapping(value = "/register", method = RequestMethod.GET)
    public Object register(HttpServletRequest request) {
        clearAttr(request);
        return this.render("/register.html");
    }


    @RequestMapping(value = "/addDesign", method = RequestMethod.GET)
    public Object addDesign(HttpServletRequest request) {
        clearAttr(request);
        return this.render("/design/design.html");
    }


    /**
     * 添加新素材
     */
    @RequestMapping(value = "/addImg", method = RequestMethod.GET)
    public Object addImg(HttpServletRequest request) {
        clearAttr(request);
        ImagesDao imagesDao = DaoFactory.getDao(ImagesDao.class);
        this.setAttr("images", imagesDao.getForHot());
        return this.render("/img/add.html");
    }


}
